var canCompleteCircuit = function (gas, cost) {
  let len = gas.length;
  let total_tank = 0;
  let cur_tank = 0;
  let starting_station = 0;
  for (let i = 0; i < len; i++) {
    total_tank += gas[i] - cost[i];
    cur_tank += gas[i] - cost[i];
    if (cur_tank < 0) {
      starting_station = i + 1;
      cur_tank = 0;
    }
  }
  return total_tank >= 0 ? starting_station : -1;
} 